package com.ruoyi.management_controller.controller;

import java.util.List;
import javax.annotation.security.PermitAll;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.management_controller.PublicOpinion.domain.PublicOpinion;
import com.ruoyi.management_controller.PublicOpinion.service.IPublicOpinionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 民情动态Controller
 * 
 * @author ruoyi
 * @date 2024-07-19
 */
@PermitAll
@RestController
@RequestMapping("/PublicOpinion/PublicOpinion")
public class PublicOpinionController extends BaseController
{
    @Autowired
    private IPublicOpinionService publicOpinionService;

    /**
     * 查询民情动态列表
     */
    //@PreAuthorize("@ss.hasPermi('PublicOpinion:PublicOpinion:list')")
    @GetMapping("/list")
    public TableDataInfo list(PublicOpinion publicOpinion)
    {
        startPage();
        List<PublicOpinion> list = publicOpinionService.selectPublicOpinionList(publicOpinion);
        return getDataTable(list);
    }

    @GetMapping("/findByVoterId")
    public TableDataInfo findByVoterId(PublicOpinion publicOpinion)
    {
        startPage();
        List<PublicOpinion> list = publicOpinionService.selectPublicOpinionList(publicOpinion);
        return getDataTable(list);
    }


    /**
     * 导出民情动态列表
     */
    @PreAuthorize("@ss.hasPermi('PublicOpinion:PublicOpinion:export')")
    @Log(title = "民情动态", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PublicOpinion publicOpinion)
    {
        List<PublicOpinion> list = publicOpinionService.selectPublicOpinionList(publicOpinion);
        ExcelUtil<PublicOpinion> util = new ExcelUtil<PublicOpinion>(PublicOpinion.class);
        util.exportExcel(response, list, "民情动态数据");
    }

    /**
     * 获取民情动态详细信息
     */
    @GetMapping(value = "/{opinionId}")
    public AjaxResult getInfo(@PathVariable("opinionId") Long opinionId)
    {
        return success(publicOpinionService.selectPublicOpinionByOpinionId(opinionId));
    }

    /**
     * 新增民情动态
     */
    @PreAuthorize("@ss.hasPermi('PublicOpinion:PublicOpinion:add')")
    @Log(title = "民情动态", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PublicOpinion publicOpinion)
    {
        return toAjax(publicOpinionService.insertPublicOpinion(publicOpinion));
    }

    /**
     * 修改民情动态
     */
    //@PreAuthorize("@ss.hasPermi('PublicOpinion:PublicOpinion:edit')")
    @Log(title = "民情动态", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PublicOpinion publicOpinion)
    {
        return toAjax(publicOpinionService.updatePublicOpinion(publicOpinion));
    }

    /**
     * 删除民情动态
     */
    @PreAuthorize("@ss.hasPermi('PublicOpinion:PublicOpinion:remove')")
    @Log(title = "民情动态", businessType = BusinessType.DELETE)
	@DeleteMapping("/{opinionIds}")
    public AjaxResult remove(@PathVariable Long[] opinionIds)
    {
        return toAjax(publicOpinionService.deletePublicOpinionByOpinionIds(opinionIds));
    }

    @GetMapping("/count")
    public TableDataInfo count(PublicOpinion publicOpinion)
    {
        startPage();
        List<PublicOpinion> list = publicOpinionService.selectPublicOpinionList(publicOpinion);
        return getDataTable(list);
    }
}
